package com.diy.springframework.step.factory;

import com.diy.springframework.step.definition.BeanDefinition;
import com.diy.springframework.step.registry.BeanDefinitionRegistry;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: diy_spring
 * @description:
 * @author: CaoYong
 * @create: 2021-07-21 09:27
 **/
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry, ConfigurableListableBeanFactory {

    private Map<String, BeanDefinition> beanDefinitionMap = new HashMap<>();

    @Override
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        beanDefinitionMap.put(beanName, beanDefinition);

    }

    @Override
    public BeanDefinition getBeanDefinition(String beanName) throws Exception {
       BeanDefinition beanDefinition = beanDefinitionMap.get(beanName);
       if (beanDefinition == null) {
           throw new Exception("No bean named" + beanName + "is defined");
       }
       return beanDefinition;
    }

    @Override
    public boolean containsBeanDefinition(String beanName) {
        return beanDefinitionMap.containsKey(beanName);
    }

    @Override
    public <T> Map<String, T> getBeansOfType(Class<T> type) throws Exception {
        return null;
    }

    @Override
    public String[] getBeanDefinitionNames() {
        return new String[0];
    }

    @Override
    public void preInstantiateSingletons() throws Exception {

    }

//    @Override
//    public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) {
//
//    }


}
